#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QtNetwork/QUdpSocket>
#include<QNetworkDatagram>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    udp=new QUdpSocket(this);
    connect(udp,&QUdpSocket::readyRead,this,&MainWindow::handle);
    udp->bind(9090);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle()
{
    const QNetworkDatagram& a=udp->receiveDatagram();
    QString s=a.data();
    QNetworkDatagram r(s.toUtf8(),a.senderAddress(),a.senderPort());
    udp->writeDatagram(r);
    ui->listWidget->addItem("client:"+s);
}

